package com.srx.elasticsearch.controller;

import com.srx.elasticsearch.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 用户查询控制器
 * <p>该类负责处理用户查询相关的操作。</p>
 * @author 沈汝旭
 * @since 2025-10-18 10:54:05
 * @version 1.0
 */
@RestController
@RequestMapping("/elasticsearch/user")
@Tag(name = "用户搜索", description = "用户搜索服务相关接口")
public class UserController
{

    /**
     * 用户服务对象
     */
    private final UserService userService;

    /**
	 * 构造函数，用于初始化用户服务对象
	 * @param userService 用户服务对象
	 */
	@Autowired
	public UserController(UserService userService)
	{
		this.userService = userService;
	}


	
	/**
	 * 根据账号获取用户ID
	 * @param account 账户名
	 * @return 用户ID
	 */
	@GetMapping("/id/{account}")
	@Operation(summary = "获取用户id", description = "根据用户账号搜索获取用户id")
	@Parameter(name = "account", description = "账号", example = "2020214555")
	public Long getUserIdByAccount(@PathVariable("account") String account) throws IOException
	{
		return userService.getUserIdByAccount(account);
	}


	/**
	 * 根据邮箱获取用户ID
	 * @param email 邮箱
	 * @return 用户ID
	 */
	@GetMapping("/id/{email}")
	@Operation(summary = "获取用户id", description = "根据用户邮箱搜索获取用户id")
	@Parameter(name = "email", description = "邮箱", example = "2017142276@qq.com")
	public Long getUserIdByEmail(@PathVariable("email") String email) throws IOException
	{
		return userService.getUserIdByEmail(email);
	}

}
